package com.panda.common.dao.redis;

import org.apache.commons.pool.impl.GenericObjectPool.Config;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.johm.JOhm;

public class RedisFactory {
	
	public RedisFactory(){

	}
	/**
	 * redis pool池
	 */
	private static JedisPool pool;

	/**
	 * redis客服端
	 */
	private static Jedis client;
	
	private static RedisFactory instance = new RedisFactory();
	
	static{
		
		try {
			RedisParam param = new RedisParam();
			if(pool==null){
				pool = new JedisPool(new Config(), param.getHost(), param.getPort());
			}
			client = pool.getResource();
			if (param.isUsingPwd()) {
				client.auth(param.getPwd());
			}
			JOhm.setPool(pool);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public static RedisFactory getInstance() {
		return instance;
	}

	public static JedisPool getPool() {
		return pool;
	}

	public static Jedis getClient() {
		return client;
	}

}
